var wxbData={};
var isTest=1;//1开发模式,2上线模式

wxbData.Ajax=function(url,d,c,b,type){
    var load,$=fui.$;
    type=type?type:'post';
    var xhr1=$.ajax({
        type:type,
        url:url,
        data:d,
        timeout:10000,
        dataType:'json',
        beforeSend:function(){
            load=layer.load(3);
            if(wxb){
                wxb.add.d.isSubmit=true
            }
            b?b():""
        },
        success:function(r){
            layer.close(load);
            if(wxb){
                wxb.add.d.isSubmit=false
            }
            if(r.code==1){
                c?c(r.result):""
            }else{
                layer.msg('错误：'+r.msg)
            }
        },
        error:function(){
            layer.close(load);
            if(wxb){
                wxb.add.d.isSubmit=false
            }
            layer.msg('请求失败');
        },
        complete :function(XMLHttpRequest,status){
            if(status=='timeout'){
                if(wxb){
                    wxb.add.d.isSubmit=false
                }
                xhr1.abort();
                layer.close(load);
                layer.msg('请求超时');
            }
        }
    })
};
//用户角色
wxbData.role=function(c){
    if(isTest==2){
        vrv.init({
            debug: false
        });
        vrv.ready(function(){
            vrv.jssdk.getAccountInfo({
                success: function (r) {
                    wxb.init.e.userID=r.mUserId;
                    var url='/Cyberspace/sys/user/'+wxb.init.e.userID;
                    wxbData.Ajax(url,'',function(r){
                        r.photoUrl=r.photoUrl||'../images/defaults-p.png';
                        wxb.init.e.userInfo={createUserInfo:r};
                        c(r.role)
                    },'','get');
                }})
        });
    }else{//测试
        wxb.init.e.userID=3;//1领导 2值班员 3地方网信办 4运营单位 5安全厂商 6专家
        var url='/Cyberspace/sys/user/'+wxb.init.e.userID;
        wxbData.Ajax(url,'',function(r){
            r.photoUrl=r.photoUrl||'../images/defaults-p.png';
            wxb.init.e.userInfo={createUserInfo:r};
            c(r.role)
        },'','get');
    }
};
//安全动态
wxbData.dynamic=function(d,c){
    var od={size:10};
    var nd=wxb.init.e.$.extend(true,{},od,d);
    wxbData.Ajax('/Cyberspace/sys/baseTable/getDynamicInformationList',nd,function(r){
        c(r)
    },'','get');
};
//首页统计
wxbData.dataCount=function(c){
    wxbData.Ajax('/Cyberspace/sys/baseTable/dataCount','',function(r){
        c(r)
    },'','get');
};
//新增信息
wxbData.add=function(type,d){
    var t=this;
    switch (type){
        case 1:
        case "1":
            t.Ajax('/Cyberspace/sys/information',d,function(){
                layer.msg('新增信息成功');
                wxb.information.d.tabType=1;
                setTimeout(function(){
                    history.go(-1);
                },1000)
            });
            break;
        case 2:
        case "2":
            t.Ajax('/Cyberspace/sys/risk',d,function(){
                layer.msg('新增风险成功');
                wxb.information.d.tabType=2;
                setTimeout(function(){
                    history.go(-1);
                },1000)
            });
            break;
        case 3:
        case "3":
            t.Ajax('/Cyberspace/sys/event',d,function(){
                layer.msg('新增事件成功');
                wxb.information.d.tabType=3;
                setTimeout(function(){
                    history.go(-1);
                },1000)
            });
            break;
    }
};
//地域列表
wxbData.region=function(c){
    wxbData.Ajax('/Cyberspace/sys/region','',function(r){
        c(r)
    },'','get');
};
//行业列表
wxbData.industry=function(c){
    wxbData.Ajax('/Cyberspace/sys/industry','',function(r){
        c(r)
    },'','get');
};
//信息类型
wxbData.type=function(type,c,sc){
    var url;
    switch (type){
        case 2:
        case '2':
            url='/Cyberspace/sys/riskType';
            wxbData.Ajax(url,'',function(r){
                c(r)
            },'','get');
            break;
        case 3:
        case "3":
            url='/Cyberspace/sys/eventType?parentID=0';
            wxbData.Ajax(url,'',function(r){
                c(r);
                wxb.init.e.$.each(r,function(m,n){
                    wxbData.Ajax('/Cyberspace/sys/eventType?parentID='+n.id,'',function(nr){
                        sc[n.id]=nr;
                    },'','get');
                });

            },'','get');
            break;
    }
};
//信息详情
wxbData.desc=function(id,c){
    var url='/Cyberspace/sys/baseTable/'+id;
    wxbData.Ajax(url,'',function(r){
        c(r)
    },'','get');
};
//预警/事件详情
wxbData.eventRiskDesc=function(id,c,type){
    var url=type==2?'/Cyberspace/sys/riskManage/':'/Cyberspace/sys/eventManage/';
    wxbData.Ajax(url+id,'',function(r){
        c(r)
    },'','get');
};
//信息转换
wxbData.change=function(d,type,c){
    delete d.createUserID;
    var url=type==2?'/Cyberspace/sys/riskManage':'/Cyberspace/sys/eventManage';
    wxbData.Ajax(url,d,function(){c()});
};
//值班员待处理信息
wxbData.dclList=function(d,c){
    var t=this;
    var nd=wxb.init.e.$.extend(true,{},d);
    nd.userID=wxb.init.e.userID;
    nd.size=10;
    t.Ajax('/Cyberspace/sys/baseTable',nd,function(r){
        c(r);
    },'','get')
};
//地方已上报
wxbData.placeList=function(d,c){
    var t=this;
    var nd=wxb.init.e.$.extend(true,{},d);
    nd.size=10;
    nd.userID=wxb.init.e.userID;
    t.Ajax('/Cyberspace/sys/baseTable',nd,function(r){
        c(r);
    },'','get')
};
wxbData.hasDclNum=function(c){
    wxbData.Ajax('/Cyberspace/sys/baseTable/pendingCount','',function(r){
        c(r['pendingCount'])
    },'','get')
};
//领导列表
wxbData.lead=function(c){
    if(wxbData.hasLead){
        c(wxbData.hasLead)
    }else{
        wxbData.Ajax('/Cyberspace/sys/user',{roleID:1},function(r){
            wxbData.hasLead={list:r};
            c(wxbData.hasLead)
        },'','get');
    }
};
//专家列表
wxbData.experts=function(c){
    if(wxbData.hasExperts){
        c(wxbData.hasExperts)
    }else{
        wxbData.Ajax('/Cyberspace/sys/user',{roleID:6},function(r){
            wxbData.hasExperts={list:r};
            c(wxbData.hasExperts)
        },'','get');
    }
};
//请示领导
wxbData.askLead=function(d,c){
    var nd=wxb.init.e.$.extend(true,{},d);
    nd.createUserID=wxb.init.e.userID;
    wxbData.Ajax('/Cyberspace/sys/todayBulletin',nd,function(){
        c();
    },'');
};
//不采用
wxbData.noUse=function(ids,c){
    var nd=('object' ===typeof ids)?ids.join(','):ids;
    wxbData.Ajax('/Cyberspace/sys/baseTable/changeStatus',{ids:nd},function(){c()},'','put');
};
//恢复
wxbData.reUse=function(id,c){
    wxbData.Ajax('/Cyberspace/sys/baseTable/restore',{id:id},function(){
        c();
    },'','put')
};
//今日快报
wxbData.todayBulletin=function(d,c){
    d.size=10;
    wxbData.Ajax('/Cyberspace/sys/todayBulletin',d,function(r){
        c(r)
    },'','get');
};
wxbData.todayDesc=function(id,c){
    wxbData.Ajax('/Cyberspace/sys/todayBulletin/'+id,'',function(r){
        c(r)
    },'','get')
};
wxbData.todayAsk=function(id,d,c){///-----确认接口
    var url='/Cyberspace/sys/bulletinApproval/'+id;
    wxbData.Ajax(url,d,function(){
        c()
    },'','put');
};
//历史信息
wxbData.historyList=function(d,c){
    var nd=wxb.init.e.$.extend(true,{},d);
    nd.size=10;
    wxbData.Ajax('/Cyberspace/sys/baseTable/history',nd,function(r){
        c(r)
    },'','get');
};
//每日零报告列表
wxbData.reportList=function(d,c){
    var od={
        size:10,
        linkdoodID:wxb.init.e.userID
    };
    var nd=wxb.init.e.$.extend(true,{},od,d);
    wxbData.Ajax('/Cyberspace/sys/dailyReport/list',nd,function(r){
        c(r)
    },'')
};
//添加每日零报告
wxbData.reportAdd=function(type,d){
    var url;
    switch (type){
        case 1://添加
            url='/Cyberspace/sys/dailyReport/addupdate';
            break;
        case 2://发布
            url='/Cyberspace/sys/dailyReport/release';
            break;
    }
    wxbData.Ajax(url,d,function(){
        if(type==1){
            layer.msg('保存成功');
            setTimeout(function(){history.back();},500)
        }else{
            layer.msg('发布成功');
            setTimeout(function(){history.back();},500)
        }
    })
};
//每日零报告详情
wxbData.reportDesc=function(type,id,c){
    var url,nd={};
    switch (type){
        case 1://领导-值班员
            url='/Cyberspace/sys/dailyReport/detail';
            nd.id=id;
            break;
        case 2://地方
            url='/Cyberspace/sys/dailyReport/detailSub';
            nd.fId=id;
            break;
    }
    wxbData.Ajax(url,nd,function(r){
        c(r)
    })
};
wxbData.reportTable=function(d,c){
    var od={size:10};
    var nd=wxb.init.e.$.extend(true,{},od,d);
    wxbData.Ajax('/Cyberspace/sys/feedbackTable/summary',nd,function(r){
        c(r)
    })
};
//地方填报零报告
wxbData.reportFeedback=function(d,c){
    wxbData.Ajax('/Cyberspace/sys/feedbackTable/update',d,function(){
        c()
    })
};
//事件/预警  --领导操作
wxbData.updateEventRisk=function(type,d,c){
    var url=type==3?'/Cyberspace/sys/eventApproval':'/Cyberspace/sys/riskApproval';
    wxbData.Ajax(url,d,function(){
        c();
    },'','put');
};
//归档
wxbData.archive=function(id,d,c){
    wxbData.Ajax('/Cyberspace/sys/baseTable/archive/'+id,d,function(){
        c()
    },'','put');
};
//事件风险列表
wxbData.getEventRisk=function(type,d,c){
    var t=this,od={size:10,userID:wxb.init.e.userID};
    var nd=wxb.init.e.$.extend(true,{},od,d);
    var url=type==2?'/Cyberspace/sys/riskManage':'/Cyberspace/sys/eventManage';
    t.Ajax(url,nd,function(r){
        c(r)
    },'','get')
};
//事件等级映射
wxbData.eventLevelToString=function(v){
    var d=['','特别重大','重大','较大','一般','其他'];
    return d[v]
};
wxbData.riskLevelToString=function(v){
    var d=['','很高','高','中等','低','很低'];
    return d[v]
};
wxbData.riskTypeToString=function(v){
    var d=['无','红','橙','黄','蓝'];
    return d[v]
};
wxbData.processStatus=function(v){
    var d=['','请示领导','专家研判','领导退回','研判完毕','值班员审核','请示上级领导','领导同意','等待下发或归档','已下发','反馈中','反馈完毕','等待归档','归档完毕'];
    return d[v]
};
wxbData.todayStatus=function(v){
    var d=['','请示领导','领导退回','值班员审核','请示上级领导','领导同意'];
    return d[v]
};
wxbData.currentStatus=function(v){
    var d=['','值班员审批','领导审批','等待研判','审批完成','等待反馈','反馈完毕','已归档'];
    return d[v]
};
wxbData.isMyDeal=function(id){
    return id==wxb.init.e.userID?'1':'0'
};
//组织架构
wxbData.orgList=function(c){
    wxbData.Ajax('/Cyberspace/sys/organizeTable/dailyOrgs','',function(r){
        c(r)
    });
};
//附件
wxbData.attachment=function(c){
    vrv.jssdk.getLocalFiles({
        size:5,
        success:function(r){
            var na=[];
            wxb.init.e.$.each(r['mFilePath'],function(x,y){
                var fn=y.substring(y.lastIndexOf('/') + 1);
                var nj={fileName:fn,fileUrl:y};
                na.push(nj);
            });
            c(na)
        }
    })
};
//我的任务
wxbData.taskList=function(d,c){
    var t=this,od={size:10,orgID:wxb.init.e.userInfo['createUserInfo']['orgID']},url;
    url=d.type==2?'/Cyberspace/sys/riskFeedbackTable/list':'/Cyberspace/sys/eventFeedbackTable/list';
    var nd=wxb.init.e.$.extend(true,{},od,d);
    delete nd.type;
    t.Ajax(url,nd,function(r){
        c(r)
    })
};
wxbData.taskList2=function(d,c){//专家
    var t=this,od={size:10};
    var nd=wxb.init.e.$.extend(true,{},od,d);
    var url=d.type==2?'/Cyberspace/sys/riskManage/getListProfessorRisk':'/Cyberspace/sys/eventManage/getListProfessorEvent';
    delete nd.type;
    t.Ajax(url,nd,function(r){
        c(r)
    },'','get')
};
wxbData.taskDesc=function(id,c,type){
    var url=type==2?'/Cyberspace/sys/riskFeedbackTable/detail':'/Cyberspace/sys/eventFeedbackTable/detail';
    wxbData.Ajax(url,{id:id},function(r){
        c(r)
    });
};
wxbData.release=function(d,type,c){
    var url=type==2?'/Cyberspace/sys/riskManage/release':'/Cyberspace/sys/eventManage/release';
    wxbData.Ajax(url,d,function () {
        c()
    })
};
wxbData.feedbackSubmit=function(d,type,c){
    var url=type==2?'/Cyberspace/sys/riskFeedbackTable/submit':'/Cyberspace/sys/eventFeedbackTable/submit';
    wxbData.Ajax(url,d,function(){
        c()
    })
};
//地方下发
wxbData.releaseSub=function(d,type,c){
    var url=type==2?'/Cyberspace/sys/riskFeedbackTable/release':'/Cyberspace/sys/eventFeedbackTable/release';
    wxbData.Ajax(url,d,function () {
        c()
    })
};
//获取运营单位列表
wxbData.Operators=function(c){
    wxbData.Ajax('/Cyberspace/sys/organizeTable/listOperators?orgID='+wxb.init.e.userInfo.createUserInfo.orgID,'',function(r){
        c(r)
    },'','get');
};
//获取地方网信办列表
wxbData.Offices=function(c){
    wxbData.Ajax('/Cyberspace/sys/organizeTable/off?id=3','',function(r){
        c(r)
    },'','get');
};
//获取安全厂商列表
wxbData.safeList=function(c){
    wxbData.Ajax('/Cyberspace/sys/organizeTable/off?id=5','',function(r){
        c(r)
    },'','get');
};
//获取反馈列表
wxbData.summary=function(type,d,c){
    var url=type==2?'/Cyberspace/sys/riskFeedbackTable/summary':'/Cyberspace/sys/eventFeedbackTable/summary';
    var od={size:10};
    od=wxb.init.e.$.extend(true,{},od,d);
    wxbData.Ajax(url,od,function(r){
        c(r)
    })
};
//流转记录
wxbData.flowList=function(fId,type,c,isResult){
    wxbData.Ajax('/Cyberspace/sys/circulationRecordTable/list',{fId:fId},function(r){
        var nr={records:[]};
        if(isResult){
            nr.records=[r[0]]
        }else{
            wxb.init.e.$.each(r,function(x,y){
                var str=y.content;
                try{
                    var nc=JSON.parse(y.content);
                    if('object'===typeof nc){
                        if(nc['superviseCase']){//安全厂商
                            str='监测情况：'+nc.superviseCase
                        }else{//地方网信办与运营单位
                            if(type==2){
                                str='情况说明:'+nc["response"]+'<br/>排查单位数量:'+nc["units"]+'<br/>排查设备数量:'+nc['devices']+"<br/>受影响单位数:"+nc['affectedUnits']+"<br/>感染病毒设备数量:"+nc['infectedDevices']+"<br/>感染病毒关键信息技术设施数量:"+nc['keyFacilityNumber']+
                                    "<br/>已清除病毒设备数量:"+nc['dumpDevices']+"<br/>已清除病毒关键信息技术设施数量:"+nc['cleanKeyFacility']
                            }else if(type==3){
                                str="情况说明:" + nc['situation'] + "<br/>系统名称:"+nc['systemName']+"<br/>IP地址:"+nc['ip']+"<br/>域名:"+nc['domain']+"<br/>漏洞URL:"+nc['behindUrl']+"<br/>操作系统版本:"+nc['osVersion']+"<br/>应用软件名称及版本:"+nc['appName']+
                                    "<br/>系统用途:"+nc['systemPurpose']+"<br/>所属单位:"+nc['unit']+"<br/>攻击来源IP地址:"+nc['attackSource']+"<br/>攻击来源地域(国家,地区):"+nc['attackRegion']
                            }
                        }
                    }
                }catch(e){}
                y.content=str;
            });
            nr.records=r;
        }
        c(nr)
    })
};
//处理操作
wxbData.operation=function(d){
    wxbData.Ajax('/Cyberspace/sys/circulationRecordTable/add',d,function(){
        location.reload()
    })
};
//批量处理
wxbData.batch=function(d){
    wxbData.Ajax('/Cyberspace/sys/circulationRecordTable/batch',d,function(){
        location.reload()
    })
};
//预警详情合计
wxbData.riskTotal=function(d,c){
    wxbData.Ajax('/Cyberspace/sys/riskFeedbackTable/total',d,function(r){
        c(r)
    })
};


//登录
wxbData.login=function(d,c){
    wxbData.Ajax('/Cyberspace/manage/login',d,function(){
        c()
    })
};
//退出
wxbData.logout=function(){
    wxbData.Ajax('/Cyberspace/manage/logout','',function(){
        sessionStorage.clear();
        location.reload()
    });
};
//修改密码
wxbData.rePassword=function(d){
    wxbData.Ajax('/Cyberspace/manage/editPassword',d,function(){
        layer.msg('修改成功,请重新登录');
        sessionStorage.clear();
        setTimeout(function(){
            location.reload()
        },300)
    })
};
//同步组织
wxbData.orgUpdate=function(c){
    wxbData.Ajax('/Cyberspace/manage/sync','',function(r){
        c(r)
    })
};
//获取组织
wxbData.getOrgList=function(d,c){
    wxbData.Ajax('/Cyberspace/sys/organizeTable/list',{orgID:d},function(r){
        c(r)
    })
};
//获取角色列表
wxbData.getRoleList=function(c){
    wxbData.Ajax('/Cyberspace/manage/role','',function(r){c(r)},'','get')
};
